package cn.itrip.biz.controller;

import cn.itrip.beans.dto.Dto;
import cn.itrip.beans.pojo.ItripUser;
import cn.itrip.beans.pojo.ItripUserLinkUser;
import cn.itrip.biz.service.ItripUserLinkUserService;
import cn.itrip.common.DtoUtils;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;


import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RequestMapping("/api")
@RestController
public class ItripUserLinkUserController {
    @Resource
    private ItripUserLinkUserService itripUserLinkUserService;


    @ApiOperation(value = "查询常用联系人", httpMethod = "POST", protocols = "HTTP", produces = "application/json", response = Dto.class, notes = "查询常用联系人")
    @RequestMapping(value = "/userinfo/queryuserlinkuser", method = RequestMethod.POST)
    public Dto selectAll(@RequestBody ItripUserLinkUser itripUserLinkUser, HttpServletRequest request)  {
        ItripUser itripUser = new ItripUser();
        try {
            return itripUserLinkUserService.selectAll(itripUserLinkUser.getLinkUserName(), itripUser.getId());
        } catch (Exception e) {
            return DtoUtils.getExcetpionDto(e,"");
        }
    }

    @ApiOperation(value = "增加联系人", httpMethod = "POST", protocols = "HTTP", produces = "application/json", response = Dto.class, notes = "增加联系人")
    @RequestMapping(value = "/userinfo/adduserlinkuser", method = RequestMethod.POST)
    public Dto insert(@RequestBody ItripUserLinkUser itripUserLinkUser){
        try {
            return itripUserLinkUserService.insert(itripUserLinkUser);
        } catch (Exception e) {
            return DtoUtils.getExcetpionDto(e,"");
        }
    }

    @ApiOperation(value = "修改联系人", httpMethod = "POST", protocols = "HTTP", produces = "application/json", response = Dto.class, notes = "修改联系人")
    @RequestMapping(value = "/userinfo/modifyuserlinkuser", method = RequestMethod.POST)
    public Dto updateByKey(@RequestBody ItripUserLinkUser itripUserLinkUser)  {
        try {
            return itripUserLinkUserService.updateByPrimaryKey(itripUserLinkUser);
        } catch (Exception e) {
            return DtoUtils.getExcetpionDto(e,"");
        }
    }

    @ApiOperation(value = "删除联系人", httpMethod = "POST", protocols = "HTTP", produces = "application/json", response = Dto.class, notes = "删除联系人")
    @RequestMapping(value = "/userinfo/deluserlinkuser", method = RequestMethod.GET)
    public Dto deleteBykey(int[] ids)  {
        try {
            return itripUserLinkUserService.deleteById(ids);
        } catch (Exception e) {
            return DtoUtils.getExcetpionDto(e,"");
        }
    }
}
